﻿Imports System.Data.OleDb

Public Class AddProgress
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSubmitProgress.Click

        Dim UserID As String
        Dim MemUser As MembershipUser
        MemUser = Membership.GetUser
        UserID = MemUser.ProviderUserKey.ToString

        Dim myGUID As New System.Guid
        myGUID = Guid.NewGuid
        Dim newFileName = myGUID.ToString() + ".jpg"

        If fuProgressPicture.HasFile Then
            Dim picLocation = Request.MapPath("pictures") & "/" & newFileName
            fuProgressPicture.SaveAs(picLocation)
        End If

        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
        Dim SqlString As String = "Insert into tblProgress (UserID, userName,Title,Description,Picture,Weight,EntryDate) Values (@f1,@f2,@f3,@f4,@f5,@f6,@f7)"
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)

        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@f1", UserID)
        cmd.Parameters.AddWithValue("@f2", User.Identity.Name)
        cmd.Parameters.AddWithValue("@f3", txtProgressTitle.Text)
        cmd.Parameters.AddWithValue("@f4", txtDescription.Text)
        cmd.Parameters.AddWithValue("@f5", "pictures/" & newFileName)
        cmd.Parameters.AddWithValue("@f6", txtWeight.Text)
        cmd.Parameters.AddWithValue("@f7", Date.Today)

        oleDbConn.Open()
        cmd.ExecuteNonQuery()


        Dim SqlPointsString As String = "Insert into tblPoints (UserID, Points, DateAdded) Values (@f1,@f2,@f3)"
        Dim cmdPoints As OleDbCommand = New OleDbCommand(SqlPointsString, oleDbConn)

        cmdPoints.CommandType = CommandType.Text
        cmdPoints.Parameters.AddWithValue("@f1", UserID)
        cmdPoints.Parameters.AddWithValue("@f2", "5")
        cmdPoints.Parameters.AddWithValue("@f3", Date.Today)

        cmdPoints.ExecuteNonQuery()
        Response.Redirect("AddProgressConfirmation.aspx")

    End Sub
End Class